package DataStuctures;

import DataStuctures.Queue.Queue;
public class LoopQueueTest<E> implements Queue {

    private E[] data;
    private int front,tail;
    private int size;


    public LoopQueueTest(int capacity) {
        data = (E[]) new Object[capacity+1];
        front = 0;
        tail = 0;
        size = 0;
    }

    public LoopQueueTest() {
        this(10);
    }

    public int getCapacity(){
        return data.length -1;
    }

    @Override
    public int getSize() {
        return size;
    }

    @Override
    public boolean isEmpty() {
        return front == tail;
    }

    @Override
    public void enqueue(Object o) {
        if((tail+1)%data.length == front){
            //resize();
        }
        data[tail] = (E) o;
        tail = (tail+1) % data.length;
        size++;
    }

    @Override
    public Object dequeue() {
        E retNode = data[front];
        data[front] = null;
        front = (front+1) % data.length;
        size--;
        return retNode;
    }

    @Override
    public Object getFront() {
        return data[front];
    }

    public void resize(int capacity){
        E[] newData = (E[]) new Object[capacity];
        for (int i = 0; i < size; i++) {
            newData[i] = data[(front + i) % data.length];
        }
        data = newData;
        front = 0;
        tail = size;
    }

}
